package com.leslie.wukong.biz.system.controller;

import com.leslie.wukong.biz.system.domain.SysUser;
import com.leslie.wukong.biz.system.domain.dto.UserLoginDTO;
import com.leslie.wukong.biz.system.domain.vo.UserLoginVO;
import com.leslie.wukong.biz.system.service.SysUserService;
import com.leslie.wukong.common.core.domain.RestResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * ClassName: TokenController
 * Package: com.leslie.wukong.biz.system.controller
 * Description:
 * @date: 2024/12/4 16:19
 * @author: itcoder
 */
@RestController
@Api(tags = "登录管理")
@Slf4j
@RequiredArgsConstructor
public class TokenController {
    private final SysUserService userService;

    @PostMapping("/login")
    @ApiOperation(value = "登录接口", tags = "登录管理")
    public RestResult<UserLoginVO> createToken(@RequestBody UserLoginDTO dto) {
        log.info("用户登录:{}", dto);
        SysUser sysUser = userService.login(dto);
        // 登录成功,生成token
        return RestResult.ok(userService.generateToken(sysUser));
    }
}
